#!/bin/bash
# Description: Exports environment vars for madde + icecc
# Author: Ragner Magalhaes <ragner.magalhaes@gmail.com>
# License: GNU GPL
# Usage: You need to change MADDE_INSTALL_DIR and ICECC_VERSION
# this script deppends of madde-icecc-create-env to create the
# tarball for ICECC_VERSION var

ICECC_BIN_DIR=/usr/lib/icecc/bin
if ! test -d "$ICECC_BIN_DIR"
then
	echo "Invalid directory for ICECC_BIN_DIR var."
	return 1
fi

# MADDE_INSTALL_DIR=/path_to_NokiaQtSDK/Maemo/version

echo "TODO: Change MADDE_INSTALL_DIR var first so delete this line!" && return 1

# You can use "mad query install-dir" to query madde install dir
MADDE_INSTALL_DIR=/opt/NokiaQtSDKv101/Maemo/4.6.2
if ! test -e "$MADDE_INSTALL_DIR/bin/mad"
then
	echo "Invalid directory for MADDE_INSTALL_DIR var."
	return 1
fi

# ICECC_VERSION=/path_to_tarball for MADDE generated by scricpt madde-icecc-create-env

echo "TODO: Change ICECC_VERSION var first so delete this line!" && return 1

ICECC_VERSION=/opt/NokiaQtSDKv101/8e05a9e0a927618bb98a19dd6bbb272b.tar.gz
if ! test -e "$ICECC_VERSION"
then
	echo "tarball for ICECC_VERSION does not exist."
	return 1
fi

tar -tzf "$ICECC_VERSION" usr/bin/arm-gcc 1>2 2>/dev/null
if ! test $?
then
	echo "tarball for ICECC_VERSION is not from MADDE."
	return 1
fi

TARGET_DIR=$("$MADDE_INSTALL_DIR/bin/mad" query target-dir)
SYSROOT_DIR=$("$MADDE_INSTALL_DIR/bin/mad" query sysroot-dir)
LIBEXEC_DIR=$(dirname $("$TARGET_DIR/bin/gcc" -print-prog-name=cc1plus))

# QTDIR=/path_to_qt on madde sysroot
QTDIR="$SYSROOT_DIR/usr/share/qt4"
PERL5LIB="$MADDE_INSTALL_DIR/madlib/perl5"

PATH="$ICECC_BIN_DIR":"$MADDE_INSTALL_DIR/bin":"$TARGET_DIR/bin":"$LIBEXEC_DIR":$PATH

export SYSROOT_DIR QTDIR PERL5LIB PATH ICECC_VERSION
